package utils

import "fmt"

type CodeAndMsg struct {
	Code    int
	Message string
	param   []any
}

func (c *CodeAndMsg) Error() string {
	if len(c.param) != 0 {
		return fmt.Sprintf(c.Message, c.param...)
	}
	return c.Message
}

// AddFormat 重新赋值占位符
func (c *CodeAndMsg) AddFormat(p ...any) *CodeAndMsg {
	c.param = p
	return c
}

var (
	Success              = &CodeAndMsg{Code: 200, Message: "成功"}                         // 成功返回
	Fail                 = &CodeAndMsg{Code: 40000, Message: "调用失败"}                     // 调用失败返回
	ParamError           = &CodeAndMsg{Code: 40001, Message: "请求参数错误"}                   // 调用失败返回
	NotAuthed            = &CodeAndMsg{Code: 40002, Message: "没有该操作权限"}                  // 调用失败返回
	NotFoundEnterpriseID = &CodeAndMsg{Code: 40003, Message: "未携带EnterpriseID,无法确认所属企业"} // 调用失败返回
)
